package binderon.com.dao.imp;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import binderon.com.dao.BaseDao;
import binderon.com.model.BaseModel;

public abstract class BaseDaoImp extends HibernateDaoSupport implements BaseDao {
	/* (non-Javadoc)
	 * @see binderon.com.dao.BaseDao#save(binderon.com.model.BaseModel)
	 */
	public BaseModel save(BaseModel bean) {
		getHibernateTemplate().save(bean);
		return bean;
	}

	/* (non-Javadoc)
	 * @see binderon.com.dao.BaseDao#update(binderon.com.model.BaseModel)
	 */
	public BaseModel update(BaseModel bean) {
		getHibernateTemplate().save(bean);
		return bean;
	}

	/* (non-Javadoc)
	 * @see binderon.com.dao.BaseDao#delete(binderon.com.model.BaseModel)
	 */
	public void delete(BaseModel bean) {
		getHibernateTemplate().delete(bean);
	}

	/* (non-Javadoc)
	 * @see binderon.com.dao.BaseDao#getById(java.lang.String)
	 */
	@SuppressWarnings("rawtypes")
	public BaseModel getById(String id) {
		List beans = getHibernateTemplate().find(
				"from " + getModelClass().getName() + " where id = ?", id);
		BaseModel result = null;
		if (!beans.isEmpty()) {
			result = (BaseModel) beans.get(0);
		}
		return result;
	}

	@SuppressWarnings("unchecked")
	public List<BaseModel> getAll() {
		return getHibernateTemplate().find("from "+getModelClass().getName());
		
	}
}
